#ifndef _SWAF_STRUCTS_
#define _SWAF_STRUCTS_

#include <string>
#include <vector>
#include <netinet/in.h>
#define ETHERNET_FRAME_MAX_SIZE 1500
typedef unsigned short u_short;
typedef unsigned char u_char;
typedef unsigned int u_int;
typedef unsigned long u_long;
using namespace std;

#define ATTACKS_LOG_FILE "/opt/swaf/logs/attacks.log"

// structs declerations
////////////////////////////////////////////////////
struct RAWIPDATA
{
	u_char data[ETHERNET_FRAME_MAX_SIZE];
	int datalen;
};
struct SESSION_STATE
{
	bool newData;
	int dataArrayIndex;
	int totalRequestsData; // in bytes
	int totalRepliesData; // in bytes
};
struct SEQACK_PARAMS
{
	u_int client_seq;
	u_int client_ack;
	u_int server_seq;
	u_int server_ack;
};
struct TCP_PARAMS
{
	string ip_src;
	string ip_dst;
	u_short src_port;
	u_short dst_port;
	bool operator==(const struct TCP_PARAMS &params)
	{
		return ( (ip_src==params.ip_src)&&(ip_dst==params.ip_dst)&&(src_port==params.src_port)&&(dst_port==params.dst_port))||
			((ip_src==params.ip_dst)&&(ip_dst==params.ip_src)&&(src_port==params.dst_port)&&(dst_port==params.src_port) );
	}
};
struct DATA
{
	int type; // 0-request, 1-reply
	string data;
};
struct HTTP_SESSION
{
	struct SESSION_STATE state;
	struct TCP_PARAMS tcpParams;
	struct SEQACK_PARAMS seqackParams;
	vector<struct DATA> httpData;
};
struct myip
{
	u_char ip_vhl;		/* header length, version */
#define IP_V(ip)	(((ip)->ip_vhl & 0xf0) >> 4)
#define IP_HL(ip)	((ip)->ip_vhl & 0x0f)
	u_char	ip_tos;		/* type of service */
	u_short	ip_len;		/* total length */
	u_short	ip_id;		/* identification */
	u_short	ip_off;		/* fragment offset field */
#define	IP_DF 0x4000			/* dont fragment flag */
#define	IP_MF 0x2000			/* more fragments flag */
#define	IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
	u_char	ip_ttl;		/* time to live */
	u_char	ip_p;		/* protocol */
	u_short	ip_sum;		/* checksum */
	struct	in_addr ip_src;
	struct	in_addr ip_dst;
};
struct mytcp
{
	u_short tcp_source_port; /*tcp source port*/
	u_short tcp_dest_port;   /*tcp dest port*/
	u_int tcp_seqno;       /*tcp sequence number*/
	u_int tcp_ackno;       /*contains the next seq num that */
	u_int tcp_res1:4;    /*little-endian*/
    u_int tcp_hlen:4;      /*length of tcp header in 32-bit words*/
#define TCP_HL(tcp)	(tcp->tcp_hlen)
	u_int tcp_fin:1;       /*Finish flag "fin"*/
   	u_int tcp_syn:1;       /*Synchronize sequence */
	u_int tcp_rst:1;      /*Reset flag */
    u_int tcp_psh:1;       /*Push */
    u_int tcp_ack:1;       /*acknowledge*/
    u_int tcp_urg:1;       /*urgent pointer*/
    u_int tcp_res2:2;
    u_short tcp_winsize;     /*maxinum number of bytes able to recieve*/
	u_short     tcp_cksum;       /*checksum */
	u_short     tcp_urgent;     /*vaild only if the urgent flag is set */

	};
#endif//_SWAF_STRUCTS_
